<template>
<view>
<pagestatus v-if="status.code !=200" :status="status" 
v-on:btnclick="getDetail"
></pagestatus>
	<block v-else>
	<view class="article-content">
	<view class="b p10 title">{{thread['title']}}</view>
<!-- #ifdef MP-WEIXIN -->
<txv-video v-if="thread['vs'] !=''" :vid="thread['vs']" width="100%" height="auto" playerid="txv0" :autoplay="true"  controls=true defn="超清" playBtnPosition="center" showProgress=true>
</txv-video>
<!-- #endif -->
<u-parse :content="thread.content" @preview="preview"/>
<image  
lazy-load="true" style="width:690upx;"
:src="imgcdn+thread['img']" mode="widthFix" 
:data-src="imgcdn+thread['img']"
@click="preview" 
></image>	
	
	
	<view class="huise">发布时间：{{thread.timestr}}</view>

	<yad  mode="main"></yad>
	</view>
	<block v-if="moredata.length>0">
	<view class="b p10">本地信息推荐</view>
	<block v-for="(newsitem,index2) in moredata" :key="index2">
<mediaItem :lc="lc" :newitem="newsitem" opentype="redirect"></mediaItem>
	<yad v-if="index2%6==4" mode="feed"></yad>
	</block>
	</block>
<view class="foot-pd"></view>


<view class="foot"><view class="row"><view class="col b c">
<view class="col_4" @click="telfun()" >TEL<view>电话</view></view>
<view class="col_4" @click="fav" >FAV<view :class="favbool?'red':''">收藏</view></view>

<view class="col_4" @click="lcfun(thread.lc)">MAP<view class="red">{{distance}}KM</view></view>
</view></view></view>
	
	</block>
	</view>
</template>

<script>
var __self=false;/*this的优化 */
var s = require('../../static/ysv8/chat.js');
var p = {
title: getApp().globalData.ysv8set.title,
id: 0,
img:getApp().globalData.ysv8set.img,
timglist:[]
}
function getimgsrc(htmlstr) {  
    var reg = /<img.+?src=('|")?([^'"]+)('|")?(?:\s+|>)/gim;  
    var imgsrcArr = []; 
	 var tem=[];
    while (tem = reg.exec(htmlstr)) {  
        imgsrcArr.push(tem[2]);  
    }  
    return imgsrcArr;  
}
	import mediaItem from '@/components/list_www.vue';
	import yad from '@/components/yad.vue'
	import pagestatus from '@/components/page-status.vue'
	import uParse from '@/components/gaoyia-parse/parse.vue'
export default {
		components: {
			mediaItem,yad,pagestatus,uParse
		},
		data() {
			return {
lc:getApp().globalData.ysv8set.lc,
anz: getApp().globalData.ysv8set.anz,
favbool: !1,
moredata: !1,
thread: false,
imgcdn: getApp().globalData.ysv8set.imgcdn,
imgswt: getApp().globalData.ysv8set.imgswt,
loadingType: "more",
    status:{
        loading:true,
        icon:'content',
        title:'页面加载中...',
        desc:'',
        showBtn:false,
        btnText:'',
        code:199
    },
				}
},onLoad: function(t) {
        if (!t.id) uni.navigateBack({});
        __self = this;
        p.id = t.id;
		if (t.lc){
		getApp().globalData.ysv8set.lc=t.lc
		this.lc=getApp().globalData.ysv8set.lc
		}
		
this.getDetail()
},onShareAppMessage: function() {
        uni.setClipboardData({data:p.title});
        return {
            title: p.title,
            content: p.title,
            path: "/pageb/shop/t?id=" + p.id,
            imageUrl: p.img
        }
},computed:{
distance(){
if(this.lc==false) return 'NAN'
return getApp().globalData.ysv8set.GetDistance(this.lc,this.thread.lc)
}		 
},methods:{
fav: function() {
var g=s.add_array(this.thread,getApp().globalData.ysv8set.datafav3,!1)[0];
getApp().globalData.ysv8set.datafav3=g
getApp().globalData.ysv8set.localStorage.setItem("datafav3"+getApp().globalData.ysv8set.apiid,JSON.stringify(g))
__self.favbool=true;

uni.showToast({
    title: '操作成功',
    mask: false
})
    },
    copytxt: function() {
        var a = __self.thread.title;
        a = a.replace(/[|]*\n/, "");
        a = a.replace(/<\/?[^>]*>/g, "");
        a = a.replace(/&npsp;/gi, "");
        uni.setClipboardData({
            data: getApp().globalData.ysv8set.title2 + a + "\n"+getApp().globalData.ysv8set.www+'www/' + p.id + ".html"
        })
    },
    setlook: function(i) {
var g=s.add_array(i["thread_data"],getApp().globalData.ysv8set.datalook3,!1)[0];
getApp().globalData.ysv8set.datalook3=g
getApp().globalData.ysv8set.localStorage.setItem("datalook3"+getApp().globalData.ysv8set.apiid,JSON.stringify(g))
__self.favbool=getApp().globalData.ysv8set.in_array(i["thread_data"]["id"],getApp().globalData.ysv8set.datafav3);
    },
getDetail: function() {
uni.request({
            url: getApp().globalData.ysv8set.www + "shop/" + p.id + ".api",
            cloudCache:getApp().globalData.ysv8set.cloudCache,
            data: {},
            success: function(e) {
if ("200" != e.data.code)
return  uni.showModal({
    title: '错误提示',
    content: e.data["info"],
    confirmText: '确定',
    success() {
        uni.navigateBack({
            fail() {
                uni.redirectTo({
                    url: '/pages/www/index'
                });
            }

        });
    }
});

e.data.thread_data["content"] = e.data.thread_data["content"].replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, '<img lazy-load="true" src="$1' + getApp().globalData.ysv8set.anz + '" style="width: 100%; border-radius: 8Px;">');
if ("img" in e.data.thread_data && e.data.thread_data.img) {
p.img = getApp().globalData.ysv8set.imgcdn + e.data.thread_data.img.split("@")[0]
p.timglist = getimgsrc(e.data.thread_data["content"])
}else{
p.timglist = [p.img];
}
p.title = e.data.thread_data["title"];
e.data.thread_data["timestr"] = getApp().globalData.ysv8set.timeStamp2String(e.data.thread_data['btime'], !0);
__self.thread=e.data.thread_data,
__self.moredata=e.data.data,
__self.status={
title:'加载完成',
showBtn:false,
code:200
}

if(getApp().globalData.ysv8set.datalook3.length>0){
    __self.setlook(e.data)
}else{
uni.getStorage({key:"datalook3"+getApp().globalData.ysv8set.apiid,success:function(t){
if(t.data)
getApp().globalData.ysv8set.datalook3=getApp().globalData.ysv8set.jsonp(t.data);
__self.setlook(e.data)
},fail:function(){
getApp().globalData.ysv8set.datalook3=[]
 __self.setlook(e.data)
}
});
uni.getStorage({key:"datafav3"+getApp().globalData.ysv8set.apiid,success:function(t){if(t.data)
getApp().globalData.ysv8set.datafav3=getApp().globalData.ysv8set.jsonp(t.data)
}
});
}
if(getApp().globalData.ysv8set.lc==false && !getApp().globalData.lcbool){
getApp().globalData.lcbool=true;
uni.getLocation({
success: function (res) {
getApp().globalData.ysv8set.lc=getApp().globalData.ysv8set.formatLocation(res.longitude, res.latitude);  
__self.lc=getApp().globalData.ysv8set.lc
uni.showToast({ title: '位置已更新'});
},fail:function(){
uni.redirectTo({
url: '/pagea/lcxz/lcxz?url='+encodeURIComponent('/pageb/shop/t?id='+p.id)
});
}});
}

},fail: function() {
__self.status={
title:'网络错误',
desc:'网络连接错误',
showBtn:true,
btnText:'重新加载',
code:400
 }
            }
        })

    }, preview(e) {
		
    uni.previewImage({
    current: e.target.dataset.src,
    urls: [e.target.dataset.src]
    })
		
    },
	lcfun:function(lc){
	let lca=lc.split(',')
	uni.openLocation({
	latitude: parseFloat(lca[0]),
	longitude: parseFloat(lca[1])	      
	});
	},telfun:function(){
		   uni.makePhoneCall({
		   phoneNumber: this.thread.tel
		   });
		   },
}
}
</script>

<style>
@import url("/components/gaoyia-parse/parse.css");
</style>
